package com.ruoyi.trainingManagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trainingManagement.domain.TrainingProgramSubject;
import com.ruoyi.trainingManagement.service.ITrainingProgramSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培养方案关联学科Controller
 * 
 * @author chenxl
 * @date 2025-08-11
 */
@RestController
@RequestMapping("/trainingManagement/trainingManagementSubject")
public class TrainingProgramSubjectController extends BaseController
{
    @Autowired
    private ITrainingProgramSubjectService trainingProgramSubjectService;

    /**
     * 查询培养方案关联学科列表
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:trainingManagementSubject:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingProgramSubject trainingProgramSubject)
    {
        startPage();
        List<TrainingProgramSubject> list = trainingProgramSubjectService.selectTrainingProgramSubjectList(trainingProgramSubject);
        return getDataTable(list);
    }

    /**
     * 导出培养方案关联学科列表
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:trainingManagementSubject:export')")
    @Log(title = "培养方案关联学科", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingProgramSubject trainingProgramSubject)
    {
        List<TrainingProgramSubject> list = trainingProgramSubjectService.selectTrainingProgramSubjectList(trainingProgramSubject);
        ExcelUtil<TrainingProgramSubject> util = new ExcelUtil<TrainingProgramSubject>(TrainingProgramSubject.class);
        util.exportExcel(response, list, "培养方案关联学科数据");
    }

    /**
     * 获取培养方案关联学科详细信息
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:trainingManagementSubject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(trainingProgramSubjectService.selectTrainingProgramSubjectById(id));
    }

    /**
     * 新增培养方案关联学科
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:trainingManagementSubject:add')")
    @Log(title = "培养方案关联学科", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingProgramSubject trainingProgramSubject)
    {
        return toAjax(trainingProgramSubjectService.insertTrainingProgramSubject(trainingProgramSubject));
    }

    /**
     * 修改培养方案关联学科
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:trainingManagementSubject:edit')")
    @Log(title = "培养方案关联学科", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingProgramSubject trainingProgramSubject)
    {
        return toAjax(trainingProgramSubjectService.updateTrainingProgramSubject(trainingProgramSubject));
    }

    /**
     * 删除培养方案关联学科
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:trainingManagementSubject:remove')")
    @Log(title = "培养方案关联学科", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(trainingProgramSubjectService.deleteTrainingProgramSubjectByIds(ids));
    }

    /*
    * 根据培养方案ID获取对应的学科列表
    */
    @GetMapping("/listByProgramId/{programId}")
    public AjaxResult listByProgramId(@PathVariable String programId) {
        List<TrainingProgramSubject> list = trainingProgramSubjectService.getSubjectsByTrainingProgramId(programId);
        System.out.println("获取到的TrainingProgramSubject"+list);
        return success(list);
    }
}
